<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 子数组的最小值之和 -->
    <script>
      var sum = function (arr) {
        let res = 0 // 结果
        let p = 0 // 首元素指针
        while (p < arr.length) {
          let q = p // 尾元素指针
          let minV = arr[p] // 保存连续子元素最小值
          while (q < arr.length) {
            minV = Math.min(minV, arr[q]) // 更新最小值
            res += minV // 将最小值加一起
            q++
          }
          p++
        }
        return res % 1000000007 // 结果对 10^9 + 7取余
      }
      // console.log(sum([3, 1, 2, 4]))
      console.log(sum([11, 81, 94, 43, 3]))
    </script>
  </body>
</html>
